#!/usr/bin/python3
# coding: utf-8
from chatbot.question_classifier_1 import *
from chatbot.question_parser_1 import *
from chatbot.answer_search_1 import *
from chatbot.baike import *

# sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8')
'''问答类'''


class ChatBotGraph:
    def __init__(self):
        self.classifier = QuestionClassifier()
        self.parser = QuestionPaser()
        self.searcher = AnswerSearcher()
        self.baike = Baike()

    @classmethod
    def chat_main(self, sent):
        self.classifier = QuestionClassifier()
        self.parser = QuestionPaser()
        self.searcher = AnswerSearcher()
        self.baike = Baike()
        answer = '您好，这个问题我爸爸还没教我，您可以问我其他问题....'
        sql_no = "MATCH (n:error) RETURN n LIMIT 1"
        res_classify = self.classifier.classify(sent)
        if not res_classify:
            return answer, sql_no
        res_sql = self.parser.parser_main(res_classify)
        final_answers = self.searcher.search_main(res_sql)
        if not final_answers:
            return answer, sql_no
        else:
            return '\n'.join(final_answers), res_sql
